@yltrcc/vditor 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.1.0 - A markdown editor written in TypeScript.
2
+ * Vditor v0.1.1 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -25,7 +25,7 @@
25
25
  *
26
26
  */
27
27
  /*!
28
- * Vditor v0.1.0 - A markdown editor written in TypeScript.
28
+ * Vditor v0.1.1 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.1.0 - A markdown editor written in TypeScript.
2
+ * Vditor v0.1.1 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -1267,7 +1267,7 @@ var looseJsonParse = function (text) {
1267
1267
  /* harmony export */ Y: () => (/* binding */ Constants),
1268
1268
  /* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
1269
1269
  /* harmony export */ });
1270
- var _VDITOR_VERSION = "0.1.0";
1270
+ var _VDITOR_VERSION = "0.1.1";
1271
1271
 
1272
1272
  var Constants = /** @class */ (function () {
1273
1273
  function Constants() {
@@ -1315,7 +1315,7 @@ var Constants = /** @class */ (function () {
1315
1315
  // 别名
1316
1316
  "js", "ts", "html", "toml", "c#", "bat"
1317
1317
  ];
1318
- Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.1.0");
1318
+ Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.1.1");
1319
1319
  Constants.MARKDOWN_OPTIONS = {
1320
1320
  autoSpace: false,
1321
1321
  gfmAutoLink: true,
@@ -7000,6 +7000,7 @@ var removeHeading = function (vditor) {
7000
7000
  ;// ./src/ts/wysiwyg/showCode.ts
7001
7001
 
7002
7002
 
7003
+
7003
7004
  /**
7004
7005
  * 显示代码编辑区域,隐藏预览区域
7005
7006
  * @param previewElement - 预览区域元素
@@ -7011,12 +7012,14 @@ var showCode = function (previewElement, vditor, first) {
7011
7012
  if (first === void 0) { first = true; }
7012
7013
  var blockElement = previewElement.parentElement;
7013
7014
  var codeElement = previewElement.previousElementSibling;
7014
- // 添加编辑状态类
7015
+ // 添加编辑状态类,通过 CSS 控制显示/隐藏
7015
7016
  blockElement.classList.add("vditor-wysiwyg__block--editing");
7017
+ // 移除内联样式,让 CSS 类控制显示
7018
+ codeElement.style.removeProperty("display");
7019
+ previewElement.style.removeProperty("display");
7016
7020
  var range = codeElement.ownerDocument.createRange();
7017
7021
  if (codeElement.tagName === "CODE") {
7018
7022
  // 行内代码
7019
- codeElement.style.display = "inline-block";
7020
7023
  if (first) {
7021
7024
  range.setStart(codeElement.firstChild, 1);
7022
7025
  }
@@ -7026,7 +7029,6 @@ var showCode = function (previewElement, vditor, first) {
7026
7029
  }
7027
7030
  else {
7028
7031
  // 代码块
7029
- codeElement.style.display = "block";
7030
7032
  if (!codeElement.firstChild.firstChild) {
7031
7033
  codeElement.firstChild.appendChild(document.createTextNode(""));
7032
7034
  }
@@ -7050,17 +7052,36 @@ var showCode = function (previewElement, vditor, first) {
7050
7052
  * @param vditor - Vditor 实例
7051
7053
  */
7052
7054
  var hideCode = function (blockElement, vditor) {
7053
- // 移除编辑状态类
7055
+ // 移除编辑状态类,通过 CSS 控制显示/隐藏
7054
7056
  blockElement.classList.remove("vditor-wysiwyg__block--editing");
7055
7057
  var codeElement = blockElement.querySelector("pre:first-child");
7056
7058
  var previewElement = blockElement.querySelector(".vditor-wysiwyg__preview");
7059
+ // 移除内联样式,让 CSS 类控制显示
7057
7060
  if (codeElement) {
7058
- codeElement.style.display = "none";
7061
+ codeElement.style.removeProperty("display");
7059
7062
  }
7060
7063
  if (previewElement) {
7061
- previewElement.style.display = "block";
7064
+ previewElement.style.removeProperty("display");
7065
+ // 从编辑区域获取代码内容
7066
+ // 编辑区域结构: <pre><code class="language-xxx">代码内容</code></pre>
7067
+ var editCodeElement = codeElement === null || codeElement === void 0 ? void 0 : codeElement.querySelector("code");
7068
+ var codeText = (editCodeElement === null || editCodeElement === void 0 ? void 0 : editCodeElement.textContent) || "";
7069
+ var language = (editCodeElement === null || editCodeElement === void 0 ? void 0 : editCodeElement.className.replace("language-", "")) || "";
7070
+ // 预览区域结构: <div class="vditor-wysiwyg__preview"><pre><code class="language-xxx">代码内容</code></pre></div>
7071
+ // 找到预览区域内部的 code 元素
7072
+ var previewCodeElement = previewElement.querySelector("pre > code");
7073
+ if (previewCodeElement) {
7074
+ // 更新预览区域的代码内容
7075
+ previewCodeElement.textContent = codeText;
7076
+ // 更新语言类名
7077
+ if (language && language !== "hljs") {
7078
+ previewCodeElement.className = "language-".concat(language);
7079
+ previewElement.setAttribute("data-language", language);
7080
+ }
7081
+ }
7062
7082
  // 重新渲染预览
7063
7083
  previewElement.setAttribute("data-render", "2");
7084
+ processCodeRender(previewElement, vditor);
7064
7085
  }
7065
7086
  };
7066
7087